package cn.gok.util.lambda;

import javax.swing.plaf.synth.SynthTextAreaUI;
import java.util.*;
import java.util.stream.Stream;

/**
 * @ClassName stream操作
 * @Description TODO
 * @Author HP
 * @Date 17:14 2022/7/11
 * @Version 1.0
 **/
class Book{
    private float price;
    private String naem;
    private int pageCount;

    @Override
    public String toString() {
        return "Book{" +
                "price=" + price +
                ", naem='" + naem + '\'' +
                ", pageCount=" + pageCount +
                '}';
    }

    public Book(float price, String naem, int pageCount) {
        this.price = price;
        this.naem = naem;
        this.pageCount = pageCount;
    }
}
public class stream操作 {
    public static void main(String[] args) {
        //流构造();
        流的中间操作();

    }

    private static void 流的中间操作() {
        List<Integer> list =Arrays.asList(100,21,10,8,21,16);
        Stream<Integer> s2 = list.stream();


        s2.filter(x-> x<100).sorted(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                if (o1>01){
                    return -1;
                }
                return 1;
            }
        }).distinct().forEach(System.out::println);

        List<Book> list1 = Arrays.asList(new Book(110f,"a",10),
                new Book(110f,"a",10));





    }

    private static void 流构造() {
        Stream s1 = Stream.of("a","b","c");
        s1.forEach(System.out::println);
        System.out.println("========================================");

        List<Integer> list = Arrays.asList(100,21,10,16);
        Stream s2 = list.stream();
        //Stream s3 =list.parallelStream();
        s2.forEach(System.out::println);


        Stream s3 = Stream.generate(()-> Math.random()).limit(10);
        s3.forEach(System.out::println);
    }
}
